/*
 * @lc app=leetcode.cn id=77 lang=javascript
 *
 * [77] 组合
 */

// @lc code=start
/**
 * @param {number} n
 * @param {number} k
 * @return {number[][]}
 */
// 1,2,3,4 2
var combine = function(n, k) {
  const res = []
  const dfs = (index, list) => {
    if (index > n + 1) return
    if (list.length === k) {
      return res.push(list.slice())
    }
    list.push(index)
    dfs(index+1, list)
    list.pop()
    dfs(index+1, list)
  }
  dfs(1, [])
  return res
};
// @lc code=end

